import { createRouter, createWebHashHistory } from 'vue-router'
import type { RouteLocationNormalized, NavigationGuardNext } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      redirect: '/scanner'
    },
    {
      path: '/scanner',
      name: 'Scanner',
      component: () => import('../views/ScannerView.vue')
    },
    {
      path: '/config',
      name: 'ProductConfig',
      component: () => import('../views/ProductConfig.vue')
    },
    {
      path: '/records',
      name: 'ScanRecords',
      component: () => import('../views/ScanRecords.vue')
    }
  ]
})

router.beforeEach((to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => {
  next()
})

// 添加全局错误处理
router.onError((error: Error) => {
  console.error('Router error:', error)
})

export default router 